package me.amiee.nicetab.demo;

import me.amiee.nicetab.library.SamplePagerItem;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.*;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;
import ohos.agp.utils.TextAlignment;
import ohos.app.Context;

import java.util.List;

/**
 * Created by dionysis_lorentzos on 6/8/14
 * for package com.lorentzos.swipecards
 * and project Swipe cards.
 * Use with caution dinausaurs might appear!
 */
public class PagerProvider extends PageSliderProvider {
    // 数据源，每个页面对应list中的一项
    private List<SamplePagerItem> list;
    private Context mContext;
    public PagerProvider(List<SamplePagerItem> list,Context context) {
        this.list = list;
        mContext=context;
    }
    private void addItems(List<SamplePagerItem> dataItems){
        list.addAll(dataItems);
        notifyDataChanged();
    }

    public List<SamplePagerItem> getList() {
        return list;
    }

    @Override
    public int getCount() {
        return list.size();
    }
    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int i) {
        final SamplePagerItem data = list.get(i);
        Component component= LayoutScatter.getInstance(mContext).parse(ResourceTable.Layout_card_layout,null,false);
        Text label = (Text) component.findComponentById(ResourceTable.Id_tv_card);
        label.setText(data.getTitle());
        componentContainer.addComponent(component);
        return component;
    }
    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {
        componentContainer.removeComponent((Component) o);
    }
    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        return true;
    }
}
